package com.ad.nbi.epirpsystem.server;

import org.omg.CORBA.ORB;
import org.omg.CORBA.ShortHolder;
import org.omg.CORBA.SystemException;
import org.omg.PortableServer.POA;

import com.ad.nbi.Constants;
import com.ad.nbi.Constants.Manager;

import CSIRPConstDefs.Result;
import CSIRPNotifications.NotifyHeartbeatOperations;
import CSIRPSystem.ConflictingHeartbeatPeriod;
import CSIRPSystem.GetCSIRPNotificationProfile;
import CSIRPSystem.GetCSIRPOperationsProfile;
import CSIRPSystem.GetCSIRPVersions;
import CSIRPSystem.GetHeartbeatPeriod;
import CSIRPSystem.InvalidHeartbeatPeriod;
import CSIRPSystem.InvalidManagerIdentifier;
import CSIRPSystem.SetHeartbeatPeriod;
import CSIRPSystem.TriggerHeartbeat;
import ManagedGenericIRPConstDefs.Method;
import ManagedGenericIRPSystem.InvalidParameter;
import ManagedGenericIRPSystem.OperationNotSupported;
import ManagedGenericIRPSystem.ValueNotSupported;

/**
 * This class is the implemetation object for your IDL interface.
 * 
 * Let the Eclipse complete operations code by choosing 'Add unimplemented
 * methods'.
 */
public class CSIRPServerImpl extends CSIRPSystem.CSIRPPOA {
	private ORB orb;

	/**
	 * Constructor for CSIRPServerImpl
	 * 
	 * @param currPoa
	 */
	public CSIRPServerImpl() {

	}

	@Override
	public Result get_heartbeat_period(ShortHolder heartbeat_period)
			throws GetHeartbeatPeriod {
		heartbeat_period.value = 10;
		return Result.SUCCESS;
	}

	@Override
	public Result set_heartbeat_period(short heartbeat_period)
			throws InvalidHeartbeatPeriod, ConflictingHeartbeatPeriod,
			OperationNotSupported, ValueNotSupported, SetHeartbeatPeriod {

		return Result.SUCCESS;
	}

	@Override
	public Result trigger_heartbeat(String manager_identifier)
			throws InvalidManagerIdentifier, TriggerHeartbeat {
		if (!Manager.FIBERHOME.equals(manager_identifier))
			throw new InvalidManagerIdentifier();
		return Result.SUCCESS;
	}

	@Override
	public String[] get_cs_irp_versions() throws GetCSIRPVersions {
		String[] version = { Constants.VERSION.CSIRP };
		return version;
	}

	@Override
	public Method[] get_cs_irp_operations_profile(String irp_version)
			throws InvalidParameter, OperationNotSupported,
			GetCSIRPOperationsProfile {
		if (!Constants.VERSION.CSIRP.equals(irp_version)) {
			throw new InvalidParameter();
		}
		Method[] methods = new Method[] {
				new Method("get_heartbeat_period",
						new String[] { "ShortHolder:heartbeat_period" }),
				new Method("set_heartbeat_period",
						new String[] { "short:heartbeat_period" }),
				new Method("trigger_heartbeat",
						new String[] { "String:manager_identifier" }),
				new Method("get_cs_irp_versions", new String[] {}),
				new Method("get_cs_irp_operations_profile",
						new String[] { "String:irp_version" }),
				new Method("get_cs_irp_notification_profile",
						new String[] { "String:irp_version" })

		};
		return methods;

	}

	@Override
	public Method[] get_cs_irp_notification_profile(String irp_version)
			throws InvalidParameter, OperationNotSupported,
			GetCSIRPNotificationProfile {
		if (!Constants.VERSION.CSIRP.equals(irp_version)) {
			throw new InvalidParameter();
		}
		Method[] methods = new Method[] { new Method(
				NotifyHeartbeatOperations.EVENT_TYPE, new String[] { "d", "e",
						"a", "b", "c", "CHANNEL_ID", "HEARTBEAT_PERIOD",
						"TRIGGER_FLAG", "MANAGER_IDENTIFIER" })

		};

		return methods;
	}

	public void setOrb(ORB orb) {
		this.orb = orb;

	}

}
